home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gnat1792.zip / gnat179b / t-adainc / s-finimp.ads < prev    next >
Text File  |  1994-05-19  |  5KB  |  103 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --    S Y S T E M . F I N A L I Z A T I O N _ I M P L E M E N T A T I O N   --
  6. --                                                                          --
  7. --                                 S p e c                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.8 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. --
  22. --                                                                          --
  23. ------------------------------------------------------------------------------
  24.  
  25. --  ??? this package should be a private package. It is set as public for now
  26. --  in order to simplify testing
  27.  
  28. package System.Finalization_Implementation is
  29.  
  30.  
  31.    type Empty_Root is abstract tagged null record;
  32.    --  Empty_Root is defined only to allow the definition of the general
  33.    --  class-wide access type Finalization_List
  34.  
  35.    type Finalizable_Ptr is access all Empty_Root'Class;
  36.  
  37.    --------------------------------------------
  38.    --  The 2 required controlled Root types  --
  39.    --------------------------------------------
  40.    --  See RM 7.6 (11)
  41.  
  42.    type Root_Controlled is tagged record
  43.       Previous : Finalizable_Ptr;
  44.       Next     : Finalizable_Ptr;
  45.    end record;
  46.  
  47.    procedure Initialize (Object : in out Root_Controlled);
  48.    procedure Finalize   (Object : in out Root_Controlled);
  49.  
  50.    Root_Part : constant Root_Controlled := (null, null);
  51.  
  52.    type Root_Limited_Controlled is tagged limited record
  53.       Previous : Finalizable_Ptr;
  54.       Next     : Finalizable_Ptr;
  55.    end record;
  56.  
  57.    procedure Initialize (Object : in out Root_Limited_Controlled);
  58.    procedure Finalize   (Object : in out Root_Limited_Controlled);
  59.  
  60.    -------------------------------------------------
  61.    --  Finalization Management Abstract Interface --
  62.    -------------------------------------------------
  63.  
  64.    Global_Final_List : Finalizable_Ptr;
  65.    --  This list stores the controlled objects defined in library-level
  66.    --  packages. They will be finalized after the main program completion.
  67.  
  68.    type Root is abstract new Empty_Root with record
  69.       Previous : Finalizable_Ptr;
  70.       Next     : Finalizable_Ptr;
  71.    end record;
  72.  
  73.    subtype Finalizable is Root'Class;
  74.    --  The classwide type for all finalizable objects
  75.  
  76.    procedure Initialize (Object : in out Root) is abstract;
  77.    procedure Finalize   (Object : in out Root) is abstract;
  78.    --  Root should logically be the common ancestor of Root_Limited_Controlled
  79.    --  and Root_Controlled. It is not possible because a limited type and a non
  80.    --  limited one cannot syntactically derive from the same ancestor.
  81.    --  Therefore, it is a different type with exactly the same characteristics,
  82.    --  and unchecked conversions will be used to go forth and back. It carries
  83.    --  the pointers used to manage the doubly linked-list of controlled objects
  84.    --  of each scope. Furthermore, Initialize and Finalize are define as
  85.    --  abstract primitives to insure the dispatch table compatibility with both
  86.    --  Root_Limited_Controlled and Root_Controlled.
  87.  
  88.    procedure Attach_To_Final_List (
  89.      L   : in out Finalizable_Ptr;
  90.      Obj : in out Finalizable);
  91.    --  Put the finalizable object on a list of finalizable elements. This
  92.    --  procedure is called during the initialization of the controlled object.
  93.  
  94.    procedure Finalize_List (L : Finalizable_Ptr);
  95.    --  Call Finalize on each element of the list L;
  96.  
  97.    procedure Finalize_One (
  98.      From : in out Finalizable_Ptr;
  99.      Obj  : in out Finalizable);
  100.    --  Call Finalize on Obj and remove it from the list From.
  101.  
  102. end System.Finalization_Implementation;
  103.